package com.fruit.controller.app.lightpay;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fruit.common.WebCommonUtil;
import com.fruit.controller.base.BaseController;
import com.fruit.pojo.lightpay.LightPayCashier;
import com.fruit.service.lightpay.LightPayManager;
import com.fruit.util.CommonUtil;
import com.fruit.util.ResultInfo;

/**
 * APP微信支付
 * 
 * @author shibeilei
 * @version 2017.11.30 12:20
 */
@Controller
@RequestMapping(value = "/app/lightpay/")
public class LightPayAppController extends BaseController {

	@Autowired
	private LightPayManager lightPayService;

	/**
	 * APP微信支付 <br/>
	 * 
	 * @param lpc
	 *            lpc
	 * @param request
	 *            request
	 * @return 返回信息
	 * @author shibeilei
	 * @version 2017.11.30 11:40
	 */
	@RequestMapping(value = "weChatPay", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String, Object> wechatPay(@RequestBody LightPayCashier lpc, HttpServletRequest request) {
		this.logBefore(logger, "APP微信支付");
		String tradeId = CommonUtil.getUUID();
		Map<String, Object> resMap = new HashMap<String, Object>();
		try {
			lpc.setIp(WebCommonUtil.getIpAddr(request));
			resMap = lightPayService.saveWechatPayCashier(tradeId, lpc);
		} catch (Exception e) {
			e.printStackTrace();
			resMap.put("result", this.initResult(ResultInfo.ERROR, "系统繁忙", null));
		}

		return resMap;

	}

}
